//
//  XSJStatusTableViewCell.swift
//  weiBo项目准备
//
//  Created by 鲜世杰 on 16/5/14.
//  Copyright © 2016年 鲜世杰. All rights reserved.
//

import UIKit
import SnapKit
let StatusTableViewCellMargin: CGFloat = 10

let HomeFontSize: CGFloat = 14

class XSJStatusTableViewCell: UITableViewCell {
    
    var toolBarTop: Constraint?
    
    var statusViewModel: XSJStatusViewModel? {
        didSet {
            originalView.statusViewModel = statusViewModel
            tooBar.statusViewModel = statusViewModel
            
            
            toolBarTop?.uninstall()
            if statusViewModel?.status?.retweeted_status != nil {
            
                retweetView.statusViewModel = statusViewModel
                retweetView.hidden = false
                tooBar.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.toolBarTop = make.top.equalTo(retweetView.snp_bottom).constraint
                    
                })
            }else{
            
                retweetView.hidden = true
                
                tooBar.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarTop = make.top.equalTo(originalView.snp_bottom).constraint
                })
                
            }
            
//            retweetView.statusViewModel = statusViewModel
        }
    }


    private lazy var originalView : XSJStatusOriginalView = XSJStatusOriginalView()
    
    private lazy var tooBar : XSJStatusToolBar = XSJStatusToolBar()
    
    private lazy var retweetView : XSJStatusRetweetView = XSJStatusRetweetView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
//        contentView.backgroundColor = RandomColor()
        //  添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(tooBar)
        //  设置约束
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(8)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        
        tooBar.snp_makeConstraints { (make) -> Void in
          self.toolBarTop = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.height.equalTo(40)
        }

        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(tooBar)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
        }
        
    }
}
